package com.ruoyi.driver.controller;

import java.util.HashMap;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.file.FileUtils;
import com.ruoyi.system.api.domain.SysFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.driver.domain.Drivers;
import com.ruoyi.driver.service.IDriversService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 司机基本信息Controller
 * 
 * @author yyj
 * @date 2025-08-17
 */
@RestController
@RequestMapping("/drivers")
public class DriversController extends BaseController
{
    private static final Logger log = LoggerFactory.getLogger(DriversController.class);

    @Autowired
    private IDriversService driversService;

    /**
     * 查询司机基本信息列表
     */
    @RequiresPermissions("driver:drivers:list")
    @GetMapping("/list")
    public TableDataInfo list(Drivers drivers)
    {
        startPage();
        List<Drivers> list = driversService.selectDriversList(drivers);
        return getDataTable(list);
    }

    /**
     * 导出司机基本信息列表
     */
    @RequiresPermissions("driver:drivers:export")
    @Log(title = "司机基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Drivers drivers)
    {
        List<Drivers> list = driversService.selectDriversList(drivers);
        ExcelUtil<Drivers> util = new ExcelUtil<Drivers>(Drivers.class);
        util.exportExcel(response, list, "司机基本信息数据");
    }

    /**
     * 获取司机基本信息详细信息
     */
    @RequiresPermissions("driver:drivers:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(driversService.selectDriversById(id));
    }

    /**
     * 新增司机基本信息
     */
    @RequiresPermissions("driver:drivers:add")
    @Log(title = "司机基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Drivers drivers)
    {
        return toAjax(driversService.insertDrivers(drivers));
    }

    /**
     * 修改司机基本信息
     */
    @RequiresPermissions("driver:drivers:edit")
    @Log(title = "司机基本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Drivers drivers)
    {
        return toAjax(driversService.updateDrivers(drivers));
    }

    /**
     * 删除司机基本信息
     */
    @RequiresPermissions("driver:drivers:remove")
    @Log(title = "司机基本信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(driversService.deleteDriversByIds(ids));
    }



    /**
     * 身份证文件上传请求
     */
    @PostMapping("uploadIdCard")
    public HashMap<String, Object> uploadIdCard(MultipartFile file)
    {
        // 上传并返回访问地址
        return driversService.uploadIdCard(file);
    }

    /**
     * 驾驶证文件上传请求
     */
    @PostMapping("uploadDrivingLicence")
    public HashMap<String, Object> uploadDrivingLicence(MultipartFile file)
    {
        // 上传并返回访问地址
        return driversService.uploadDrivingLicence(file);
    }

    /**
     * 行驶证文件上传请求
     */
    @PostMapping("uploadVehicleLicense")
    public HashMap<String, Object> uploadVehicleLicense(MultipartFile file)
    {
        // 上传并返回访问地址
        return driversService.uploadVehicleLicense(file);
    }

}
